<template>
  <div class="specialist-box">
    <template v-if="showRoot">
      <!-- <div class='job-banner ct'>
        <div class="banner-text">
          <div class="c-new-title">
            专家队伍
          </div>
          <div class="c-new-text">
            “站院联建”农技推广服务平台
          </div>
        </div>
      </div> -->
      <div class="s-content ct">
        <div class="s-t-t">
          <div class="s-top">
            <div class="s-label">区域：</div>
            <div class="s-item-l ssitem cp" @click="cityclick()" :class="{'s-active': !cityac}">
              全部
            </div>
            <div class="s-item">
              <div class="ssitem cp" :class="{'s-active': item==cityac}" @click="cityclick(item)" v-for="item in citys">
              {{ item }}
              </div>
            </div>
          </div>
          <div class="s-search">
            <div>按关键词搜索: </div>
            <el-input v-model="input2" class="s-input" @keyup.enter="search1">
              <template #append>
                <div class="s-input-ti cp" @click="search1" >搜索</div>
              </template>
            </el-input>
          </div>
        </div>

        <div class="s-bottom">
          <div class="b-item" @click="to(item)" v-for="item in specList">
            <img :src="item.photo" alt="">
            <div class="item-info">
              <div class="info-name">{{ item.name }}</div>
              <div class="info-t oo">{{ item.workUnit }}</div>
              <div class="info-t ooo">{{ item.courtyardName || '' }}</div>
            </div>
          </div>
        </div>
        <div class="item-page">
          <el-pagination v-model:current-page="currentPage3" :page-size="currentPageSize3"
            layout="prev, pager, next, jumper" prev-text="上一页" next-text="下一页" :total="total"
            @current-change="pagechange" />
        </div>
      </div>
    </template>
    <router-view></router-view>
  </div>
</template>
<script setup>
import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
import { pageProfessor, getlistCity } from '@/api/home'

const currentPage3 = ref(1)
const total = ref(0)
const specList = ref([])
const router = useRouter();
const currentPageSize3 = ref(15)
const input2 = ref('')
const citys = ref([]);
const cityac = ref('')

const getcitys = async () => {
  const datas = await getlistCity();
  console.log('datas', datas)
  if(datas?.data?.length) {
    citys.value = datas.data;
  }
}

getcitys();

const cityclick = (item) => {
  cityac.value = item;
  setSpeclist(input2.value);
}

const to = (item) => {
  router.push(`/specialist/specialistDetail/${item.professorId}`)
}
const showRoot = computed(() => {
  return router?.currentRoute?.value?.meta?.id == 0
})

async function setSpeclist(name='') {
  const params = {
    params: {
      status: true,
      name,
      area: cityac.value
    },
    page: {
      pageSize: currentPageSize3.value,
      pageNum: currentPage3.value,
    }
  }
  const { data } = await pageProfessor(params)
  total.value = data?.total || 0
  specList.value = data?.list || []
}

const search1 = () => {
  setSpeclist(input2.value);
}

const pagechange = (page) => {
  currentPage3.value = page;
  setSpeclist('')
}

setSpeclist();


</script>
<style lang="scss" scoped>
.specialist-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  color: #777;
  min-height: 900px;
  overflow: hidden;
  flex: 1;

  .job-banner {
    width: 100%;
    height: 280px;
    background: url(../../assets/speciallist/1.png) no-repeat center center / cover;
    padding: 0 10%;
    display: flex;
    align-items: center;
    color: #fff;

    .banner-text {
      padding-left: 30px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      position: relative;

      &::after {
        position: absolute;
        left: 0;
        top: 12px;
        height: 84%;
        width: 4px;
        background-color: #fff;
        content: ''
      }

      .c-new-title {
        font-weight: 700;
        font-size: 50px;
      }

      .c-new-text {
        font-size: 30px;
      }
    }
  }

  .s-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f8f8 url('../../assets/job/6.png') no-repeat 0 200px;
    min-height: 1000px;
    width: 100%;
    padding: 0 10%;
    margin-top: 30px;
    font-size: 22px;

    .s-t-t {
      width: 100%;
      min-height: 270px;
      padding: 40px;
      background-color: #fff;
      margin-bottom: 35px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .s-top {
      display: flex;
      align-items: flex-start;

      .s-label {
        margin-right: 20px;
      }

      .s-item {
        display: flex;
        flex-wrap: wrap;
        flex: 1;
        overflow: hidden;
      }

      .ssitem {
        padding: 2px 20px;
        margin-right: 10px;
        margin-bottom: 30px;

        &.s-active {
          background-color: #068043;
          color: #fff;
        }
      }
    }

    .s-search {
      display: flex;
      align-items: center;

      :deep(.s-input) {
        margin-left: 50px;
        font-size: 20px;
        height: 42px;
        width: 450px;

        .el-input__wrapper {
          background-color: #f5f5f5;
          box-shadow: none;
        }

        .el-input-group__append {
          background-color: red;
          color: #fff;
          background-color: #068043;
          height: 100%;
        }
      }
    }

    .s-bottom {
      width: 100%;
      min-height: 900px;
      display: flex;
      flex-wrap: wrap;
      // justify-content: space-between;

      .b-item {
        display: flex;
        height: 215px;
        width: 32.5%;
        margin-bottom: 40px;
        background-color: #fff;
        margin-right: 10px;
        cursor: pointer;

        img {
          // width: 170px;
          height: 100%;
          object-fit: contain;
        }

        .item-info {
          height: 100%;
          flex: 1;
          overflow: hidden;
          padding: 20px;
          font-size: 16px;

          .info-name {
            font-size: 30px;
            font-weight: bold;
            color: #000;
            margin-bottom: 15px;
          }

          .info-t {
            margin-bottom: 10px;
          }
        }
      }
    }

    .item-page {
      height: 160px;
      display: flex;
      align-items: center;
      justify-content: center;

      :deep(.el-pagination) {

        button,
        li {
          background-color: transparent;
          width: 50px;
          height: 50px;
          border: 2px solid #e5e5e5;
          border-radius: 5px;
          color: #777;
          font-size: 24px;
          font-weight: normal;
          margin-right: 30px;
        }

        button {
          border: 0 none;
        }

        .el-pagination__jump {
          color: #777;
          font-size: 26px;
        }

        .el-pagination__editor {
          min-width: 50px;
          min-height: 50px;
          font-size: 24px;
        }

        .el-input__wrapper {
          padding: 0;
        }

        .el-input__inner {
          color: #777 !important;
        }
      }
    }
  }
}
</style>